cmake_minimum_required(VERSION 3.5)

project(EventX VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

set(PROJECT_SOURCES
        main.cpp
        widget.cpp
        widget.h
)

file(GLOB STACK_WIDGET ${CMAKE_SOURCE_DIR}/StackWidget/*.cpp)
include_directories(${CMAKE_SOURCE_DIR}/StackWidget)

set(CMAKE_CXX_FLAGS "-Wl,--as-need -fPIE -flto -Wall")

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(EventX
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
		${STACK_WIDGET}
		StackWidget/Event/labelx.h StackWidget/Event/labelx.cpp
		StackWidget/Event/mouse.h StackWidget/Event/mouse.cpp
                StackWidget/Event/keyevent.h StackWidget/Event/keyevent.cpp
    )

else()
    if(ANDROID)
        add_library(EventX SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(EventX
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(EventX PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)


if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(EventX)
endif()
